The pathPrior() function is named after the term a priori. For a given input piece and square of the chessboard, it returns the path the piece can take on an empty chessboard, prior to the circumstance that arise when a game is in play.
The pawn is the only piece unable to move backwards, and its direction depends on its color.
1
pathPrior(piece = "black pawn", square = "e5")
1
## [1] "e4" "d4" "f4"
1
pathPrior(piece = "white pawn", square = "e5")
1
## [1] "e6" "d6" "f6"
It is the only piece whose color needs to be specified for pathPrior.() to work effectively. Post.() functions are conversely named after the term a posteriori. They trim each piece’s options according to the circumstances of the entire board.
They cannot be used unless a snapshot of the chessboard’s position exists for them to analyze. The snapshots exist as rows of the position data frame, which has one variable for each square of the chessboard. Each variable in position is a square of the chessboard,
## c6 g7 d7 g3 h8 a6 d2 g6 ## 000_zero <NA> black pawn black pawn <NA> black Rook <NA> white pawn <NA> ## h7 h3 ## 000_zero black pawn <NA>
The first row is the empty chessboard, with no pieces listed for any of the squares. The second row is the zero position, with pieces set at starting positions.
We can compare the mobility of a white knight on b1 before and after the pieces are set up:
1
pathPrior(piece = "knight", square = "b1")
1
## [1] "c3" "a3" "d2"
1
pathPost.(square = "b1", game_pgn = "000_zero")
1
## [1] "c3" "a3"
Because of the game_pgn input, pathPost. knows that the piece on h2 is a white knight, and that it cannot move to d2 because that space is occupied by another pawn.
Let us begin by observing the game I am currently playing. We can modify the link into the format “http://username:password@chess.com/…” and pass it to the rawToTidy() function as follows:
1 2 3 4 5 6 7 8 9 10
LinkID <- 131764454 Username <- "thinkboolean" Password <- "blogChess"# counting on you not to abuse this; feel free to contact me for details Link <- paste("http://", Username, ":", Password, "@chess.com/echess/game?id=", LinkID) print(Link)
The first move is pawn to e4. Inputing it into the newPosition() function replicates the last (or specified) row of the position frame, places the white pawn on e4, and removes it from e2.